package com.ayf.payment.game.api.controller.platform;

import com.ayf.payment.game.api.dto.platform.PaymentProductDTO;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.service.platform.PaymentProductService;
import com.ayf.payment.game.api.type.CommonConstants;
import com.ayf.payment.game.api.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 支付产品
 *
 * @author wwl
 * @date 2020/3/7 18:38
 */
@RequestMapping("/t/payment")
@RestController
public class PaymentProductController {

    @Autowired
    private PaymentProductService paymentProductService;

    /**
     * 获取支付产品列表
     * @return
     */
    @PostMapping("/product/selectAll")
    public CommonResult<List<PaymentProductDTO>> selectPaymentChannel() {
        List<PaymentProductDTO> list=paymentProductService.selectAll();
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "查询成功", list);
    }

    /**
     * 获取支付产品详情
     * @return
     */
    @PostMapping("/getPaymentProduct")
    public CommonResult<PaymentProductDTO> getPaymentProduct(@RequestBody PaymentProductDTO paymentProductDTO) {
        if(paymentProductDTO==null){
            throw new ParameterException("参数不能为空");
        }
        if(paymentProductDTO.getId()==null){
            throw new ParameterException("ID不能为空");
        }
        PaymentProductDTO db=paymentProductService.getPaymentProduct(paymentProductDTO.getId());
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "查询成功", db);
    }

    /**
     * 修改支付产品状态
     * @return
     */
    @PostMapping("/updateProductStatus")
    public CommonResult updateProductStatus(@RequestBody PaymentProductDTO paymentProductDTO) {
        if(paymentProductDTO==null){
            throw new ParameterException("参数不能为空");
        }
        if(paymentProductDTO.getId()==null){
            throw new ParameterException("ID不能为空");
        }
        paymentProductService.updateProductStatus(paymentProductDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "修改成功", "");
    }

    /**
     * 修改支付产品序列
     * @param paymentProductDTO
     * @return
     */
    @PostMapping("/updateSerialNumber")
    public CommonResult<List<PaymentProductDTO>> updateSerialNumber(@RequestBody PaymentProductDTO paymentProductDTO) {
        if(paymentProductDTO==null){
            throw new ParameterException("参数不能为空");
        }
        if(paymentProductDTO.getId()==null){
            throw new ParameterException("ID不能为空");
        }
        List<PaymentProductDTO> list=paymentProductService.updateSerialNumber(paymentProductDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "成功", list);
    }

    /**
     * 修改支付产品详情
     * @param paymentProductDTO
     * @return
     */
    @PostMapping("/updatePaymentProduct")
    public CommonResult updatePaymentProduct(@RequestBody PaymentProductDTO paymentProductDTO) {
        if(paymentProductDTO==null){
            throw new ParameterException("参数不能为空");
        }
        if(paymentProductDTO.getId()==null){
            throw new ParameterException("ID不能为空");
        }
        paymentProductService.updatePaymentProduct(paymentProductDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "成功", "");
    }
}
